#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#ifdef __linux__
#include <sys/kd.h>
#endif
#include <sys/resource.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <time.h>
#include <fcntl.h>
#include <string.h>
#include <signal.h>
#include <termios.h>
#ifdef __FreeBSD__
#include <utmpx.h>
#else
#include <utmp.h>
#endif
#include <ctype.h>
#include <stdarg.h>
#include <sys/ttydefaults.h>
#include <sys/syslog.h>
#include <sys/time.h>
/*
 * inittab.d
 */
#include <sys/types.h>
#include <dirent.h>

#ifdef WITH_SELINUX
#  include <selinux/selinux.h>
#endif
#ifdef __FreeBSD__
extern char **environ;
#endif

#ifdef __i386__
#  ifdef __GLIBC__
     /* GNU libc 2.x */
#    define STACK_DEBUG 1
#    if (__GLIBC__ == 2 && __GLIBC_MINOR__ == 0)
       /* Only glibc 2.0 needs this */
#      include <sigcontext.h>
#    elif ( __GLIBC__ > 2) && ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1))
#      include <bits/sigcontext.h>
#    endif
#  endif
#endif

#include "../init.h"
#include "../initreq.h"
#include "../paths.h"
#include "../reboot.h"
#include "../runlevellog.h"
#include "../set.h"

#ifndef SIGPWR
#  define SIGPWR SIGUSR2
#endif

#ifndef CBAUD
#  define CBAUD		0
#endif
#ifndef CBAUDEX
#  define CBAUDEX	0
#endif

/* Set a signal handler. */
#define SETSIG(sa, sig, fun, flags) \
		do { \
			memset(&sa, 0, sizeof(sa)); \
			sa.sa_handler = fun; \
			sa.sa_flags = flags; \
			sigemptyset(&sa.sa_mask); \
			sigaction(sig, &sa, NULL); \
		} while(0)


static int 
read2_inittab() {
	
	  FILE		*fp;			/* The INITTAB file */
	  FILE		*fp_tab;		/* The RCD files */
	  CHILD		*ch, *old, *i;		/* Pointers to CHILD structure */
	  CHILD		*head = NULL;		/* Head of linked list */
	#ifdef INITLVL
	  struct stat	st;			/* To stat INITLVL */
	#endif
	  sigset_t	nmask, omask;		/* For blocking SIGCHLD. */
	  char		buf[256];		/* Line buffer */
	  char		err[64];		/* Error message. */
	  char		*id, *rlevel, *action, *process;	/* Fields of a line */
	  char		*p;
	  int		lineNo = 0;		/* Line number in INITTAB file */
	  int		actionNo;		/* Decoded action field */
	  int		f;				/* Counter */
	  int		round;			/* round 0 for SIGTERM, 1 for SIGKILL */
	  int		foundOne = 0;	/* No killing no sleep */
	  int		talk;			/* Talk to the user */
	  int		done = -1;		/* Ready yet? , 2 level : -1 nothing done, 0 inittab done, 1 inittab and inittab.d done */
	  DIR 		*tabdir=NULL;	/* the INITTAB.D dir */
	  struct dirent *file_entry;/* inittab.d entry */
	  char 		f_name[272];	/* size d_name + strlen /etc/inittad.d/ */

#if DEBUG
	if (newFamily != NULL) {
		INITDBG(L_VB, "PANIC newFamily != NULL");
		exit(1);
	}
	INITDBG(L_VB, "Reading inittab");
#endif
	/* OPEN INITTAB READ */
	if ((fp = fopen(INITTAB, "r")) == NULL) initlog(L_VB, "No inittab file found");
	/* OPEN RC.D */
	if( (tabdir = opendir(INITTABD))==NULL) initlog(L_VB, "No rc.d directory found");
    while (done != 1) {
		if( done == -1 ){
			if(fp == NULL || fgets(buf, sizeof(buf), fp) == NULL) {
				done = 0;
				for(old = newFamily; old; old = old->next)
					if (strpbrk(old->rlevel, "S")) break ;
				if (old == NULL)
					snprintf(buf, sizeof(buf), "~~:S:wait:%s\n", SULOGIN);
				else
					continue;	
			}
		}else if (done == 0 ) {

		}
	}
	/*RETURN 0*/
	return 0;
}
int 
main(){
    return 0;
}
